package com.example.demo.commons.core.robot.message;

import cn.hutool.core.util.ArrayUtil;
import com.example.demo.commons.core.robot.message.base.BaseMessage;
import com.example.demo.commons.core.robot.message.base.Constants;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class TextMessage extends BaseMessage<TextMessage> {
    private String content;
    private String[] mentioned_mobile_list;

    private TextMessage(String content, String... mobiles) {
        super(Constants.TEXT);
        this.content = content;
        this.mentioned_mobile_list = mobiles;
    }

    public static TextMessageBuilder builder() {
        return new TextMessageBuilder();
    }


    public static class TextMessageBuilder {
        private String content;
        private String[] mobiles;

        TextMessageBuilder() {
        }

        public TextMessageBuilder content(String content) {
            this.content = content;
            return this;
        }

        public TextMessageBuilder atAll() {
            if (this.mobiles != null && this.mobiles.length > 0) {
                ArrayUtil.append(this.mobiles, Constants.ALL);
            } else {
                this.mobiles = new String[]{Constants.ALL};
            }
            return this;
        }

        public TextMessageBuilder at(String... mobiles) {
            this.mobiles = mobiles;
            return this;
        }

        public TextMessage build() {
            return new TextMessage(this.content, this.mobiles);
        }
    }
}
